﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Web.Compilation;

using $prjsn$.Entity.Services;

using ProjectBase.Core;

namespace $safeprojectname$.Providers
{
    /// <summary>
    ///     Provides the ASP.NET 'resource' functionality based on ResourceManager
    /// </summary>
    public class ResourceProvider : IResourceProvider
    {
        #region members
        readonly string _area = string.Empty;
        ResourceFinder _resourceFinder;
        #endregion members

        #region constructor
        /// <summary>
        ///     Creates provider with the distinguishing area information
        /// </summary>
        /// <param name = "area"></param>
        public ResourceProvider(string area)
        {
            _area = area;
        }
        #endregion constructor

        #region IResourceProvider Members
        /// <summary>
        ///     Provides the best way how to use resources (prefered).
        ///     Returns string based on culture, key and area (comming from Factory in this constructor)
        /// </summary>
        /// <param name = "resourceKey"></param>
        /// <param name = "culture"></param>
        /// <returns></returns>
        public object GetObject(string resourceKey, CultureInfo culture)
        {
            if (culture.IsNull())
            {
                culture = CultureInfo.CurrentUICulture;
            }
            return ResourceFinder.GetResourceByCultureAndKey(culture, resourceKey, _area);
        }

        /// <summary>
        ///     This is used by 'meta:resourceKey="Detail"' attributes on ASP.NET webcontrols.
        /// </summary>
        public IResourceReader ResourceReader
        {
            get
            {
                var result = new ResourceReader(
                    ResourceFinder.GetDictionaryByCultureAndArea(
                        CultureInfo.CurrentUICulture,
                        _area));
                return result;
            }
        }
        #endregion

        #region properties
        protected virtual ResourceFinder ResourceFinder
        {
            get { return _resourceFinder ?? (_resourceFinder = new ResourceFinder()); }
        }
        #endregion properties
    }
}